<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 参考文档 - Types/Hash.Extras</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Hash">Hash</a></h4>
      <div class="menu-item"><a href="#Hash:getFromPath">getFromPath</a></div>
      <div class="menu-item"><a href="#Hash:cleanValues">cleanValues</a></div>
      <div class="menu-item"><a href="#Hash:run">run</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1 id="Hash"><a href="#Hash">类型: Hash</a></h1>
      <p class="description">A collection of Hash methods.</p>
      <h3>Note</h3>
      <p>Hash Extras is kept for compatibility reasons. It is expected to be removed with the MooTools 2.0 release. It is encouraged to use <a href="../../../docs/more/Types/Object.Extras.html">Object.Extras</a> instead.</p>
      <h3>Tutorial/Demo</h3>
      <ul>
        <li><a href="http://www.clientcide.com/wiki/cnet-libraries/03-native/02-hash.extras">Online Tutorial/Demo</a></li>
      </ul>
      <h3>See Also</h3>
      <ul>
        <li>[Mootools:Hash][]</li>
      </ul>
      <h2 id="Hash:getFromPath"><a href="#Hash:getFromPath">Hash Method: getFromPath</a></h2>
      <p class="description">Returns a value of an object by its path.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myHash.<span class="me1">getFromPath</span><span class="br0">(</span>path<span class="br0">)</span>;
</pre>
      <h3>Arguments</h3>
      <ol>
        <li>path - (<em>string</em>) the path to the key for the value you wish to retrieve</li>
      </ol>
      <h3>Returns</h3>
      <ul>
        <li>(<em>null</em> or <em>mixed</em>) if the path has no value, <em>null</em> is returned; otherwise the value that corresponds to the path is returned.</li>
      </ul>
      <h3>Example</h3>
      <pre class="javascript">#H<span class="br0">(</span><span class="br0">{</span>
    food: <span class="br0">{</span>
        fruits: <span class="br0">{</span>
            apples: <span class="st0">"red"</span>,
            lemon: <span class="st0">"yellow"</span>

        <span class="br0">}</span>
    <span class="br0">}</span>
<span class="br0">}</span><span class="br0">)</span>.<span class="me1">getFromPath</span><span class="br0">(</span><span class="st0">"food.fruits.apples"</span><span class="br0">)</span>;
<span class="co1">//returns "red"</span>
</pre>
      <h2 id="Hash:cleanValues"><a href="#Hash:cleanValues">Hash Method: cleanValues</a></h2>
      <p class="description">Removes values from the Hash.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myHash.<span class="me1">cleanValues</span><span class="br0">(</span>method<span class="br0">)</span>;
</pre>
      <h3>Arguments</h3>
      <ol>
        <li>method - (<em>function</em>) The function that each value in the Hash is passed. If it returns <strong>true</strong> the value is kept. Defaults to <strong>[$defined][]</strong>.</li>
      </ol>
      <h3>Returns</h3>
      <ul>
        <li>(<em>Hash</em>) - This Hash.</li>
      </ul>
      <h3>Example</h3>
      <pre class="javascript">$H<span class="br0">(</span><span class="br0">{</span>
    foo: <span class="st0">'bar'</span>,
    something: <span class="st0">'else'</span>,
    missing: <span class="kw2">null</span>

<span class="br0">}</span><span class="br0">)</span>.<span class="me1">cleanValues</span><span class="br0">(</span><span class="br0">)</span>;
&nbsp;
<span class="co1">//remove all values &lt; 0</span>
$H<span class="br0">(</span><span class="br0">{</span>
    a: <span class="nu0">-1</span>,
    b: <span class="nu0">2</span>,
    c: <span class="nu0">0</span>,
    d: <span class="nu0">-5</span>

<span class="br0">}</span><span class="br0">)</span>.<span class="me1">cleanValues</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span>value<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">if</span> <span class="br0">(</span>$type<span class="br0">(</span>value<span class="br0">)</span> != <span class="st0">"number"</span><span class="br0">)</span> <span class="kw1">return</span> <span class="kw2">true</span>;
    <span class="kw1">return</span> value &gt; <span class="nu0">0</span>;

<span class="br0">}</span><span class="br0">)</span>;
</pre>
      <h2 id="Hash:run"><a href="#Hash:run">Hash method: run</a></h2>
      <p class="description">Runs all the methods that are values of the hash.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myHash.<span class="me1">run</span><span class="br0">(</span><span class="br0">)</span>

</pre>
      <h3>Example</h3>
      <pre class="javascript"><span class="kw2">var</span> myPage = <span class="br0">{</span>
    init: <span class="kw2">new</span> Hash<span class="br0">(</span><span class="br0">{</span>

        setupNav: <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
            <span class="co1">//set up the nav</span>
        <span class="br0">}</span>,
        setupSearch: <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>

            <span class="co1">//set up the search</span>
        <span class="br0">}</span>
    <span class="br0">}</span><span class="br0">)</span>
<span class="br0">}</span>;
window.<span class="me1">addEvent</span><span class="br0">(</span><span class="st0">'domready'</span>, myPage.<span class="me1">init</span>.<span class="me1">run</span>.<span class="me1">bind</span><span class="br0">(</span>myPage.<span class="me1">init</span><span class="br0">)</span><span class="br0">)</span>;

</pre>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
